package com.b1502.store2.adapter;

import android.content.Context;

import android.view.View;


import android.view.ViewGroup;
import android.widget.BaseAdapter;


import android.widget.TextView;



import com.b1502.store2.R;
import com.b1502.store2.model.bean.ProductBean;


import java.util.List;

/**
 * 类描述:
 * 作者：陈文梦
 * 时间:2017/3/1 20:08
 * 邮箱:18310832074@163.com
 */

public class ProductAdapter extends BaseAdapter {

    private Context context;
    private List<ProductBean.ArgumentsBean> argumentsBeanList;


    public ProductAdapter(List<ProductBean.ArgumentsBean> argumentsBeanList, Context context) {
        this.argumentsBeanList = argumentsBeanList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return argumentsBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return argumentsBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        MyViewHolder myViewHolder=null;

        if(convertView==null){
            myViewHolder =new MyViewHolder();
            convertView=View.inflate(context, R.layout.product_list_item,null);
            myViewHolder.textView1= (TextView) convertView.findViewById(R.id.t1);
            myViewHolder.textView2= (TextView) convertView.findViewById(R.id.t2);
            convertView.setTag(myViewHolder);

        }else {
            myViewHolder= (MyViewHolder) convertView.getTag();

        }
        myViewHolder.textView1.setText(argumentsBeanList.get(position).getKey());
        myViewHolder.textView2.setText(argumentsBeanList.get(position).getValue());
        return convertView;
    }

    class MyViewHolder{

        TextView textView1,textView2;
    }
}
